﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using Application = Microsoft.Office.Interop.Word.Application;

namespace SetLanguageInfo
{
    public partial class test : Form
    {
        public test()
        {
            InitializeComponent();
        }

        private void btnConvert_Click(object sender, EventArgs e)
        {
            string src = txtSrc.Text;
            string des = SC2TC(src);
            txtTar.Text = des;
        }


        public string TC2SC(string strSource)
        {
            string strResult;
            _Application objWord = new Microsoft.Office.Interop.Word.Application();
            object t = Missing.Value;
            object nt = Missing.Value;
            object dt = Missing.Value;
            object v = true;
            Document objDocument = objWord.Documents.Add(ref t, ref nt, ref dt, ref v);
            objWord.Selection.TypeText(strSource);
            objWord.Selection.Range.TCSCConverter(WdTCSCConverterDirection.wdTCSCConverterDirectionTCSC, true, true);
            objWord.ActiveDocument.Select();
            strResult = objWord.Selection.Text;
            object sc = 0;
            object of = Missing.Value;
            object rd = Missing.Value;
            objWord.Quit(ref sc, ref of, ref rd);
            objDocument = null;
            objWord = null;
            return strResult;
        }
        public string SC2TC(string strSource)
        {
            string strResult;
            _Application objWord = new Microsoft.Office.Interop.Word.Application();
            object t = Missing.Value;
            object nt = Missing.Value;
            object dt = Missing.Value;
            object v = true;
            Document objDocument = objWord.Documents.Add(ref t, ref nt, ref dt, ref v);
            objWord.Selection.TypeText(strSource);
            objWord.Selection.Range.TCSCConverter(WdTCSCConverterDirection.wdTCSCConverterDirectionSCTC, true, true);
            objWord.ActiveDocument.Select();
            strResult = objWord.Selection.Text;
            object sc = 0;
            object of = Missing.Value;
            object rd = Missing.Value;
            objWord.Quit(ref sc, ref of, ref rd);
            objDocument = null;
            objWord = null;
            return strResult;
        }

        public static void ss()
        {
            _Application objWord = new Application();
            object t = Missing.Value;
            object nt = Missing.Value;
            object dt = Missing.Value;
            object v = Missing.Value;
            Document objDocument = objWord.Documents.Add(ref t, ref nt, ref dt, ref v);
            object sc = 0;
            object of = Missing.Value;
            object rd = Missing.Value;
            objWord.Quit(ref sc, ref of, ref rd);
            objDocument = null;
            objWord = null;
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ss();
        }
    }
}
